package com.cxhc.app.api.hcdoc;


import com.cxhc.app.api.hcdoc.vo.HdBranchBudgetModifyLogVo;
import com.cxhc.app.api.hcdoc.vo.HdBranchInfoVo;
import com.cxhc.app.api.hcdoc.vo.HdUserBranchVo;
import com.cxhc.app.api.mapper.hcdoc.HdBranchBudgetModifyLogMapStructMapper;
import com.cxhc.app.api.mapper.hcdoc.HdBranchInfoMapStructMapper;
import com.cxhc.app.api.mapper.hcdoc.HdUserBranchInfoMapStructMapper;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.system.domain.hcdoc.HdBranchBudgetModifyLog;
import com.cxhc.system.domain.hcdoc.HdBranchInfo;
import com.cxhc.system.domain.hcdoc.HdUserBranch;
import com.cxhc.system.service.hcdoc.HdBranchInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 预算单位Controller
 *
 * @author Dhq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/api/hcDoc/hdBranchInfo")
public class HdBranchInfoApi extends BaseController {

    @Autowired
    private HdBranchInfoService hdhcDocUserService;


    /**
     * 查询预算单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HdBranchInfoVo hdBranchInfoVo) {
        HdBranchInfo hdBranchInfo = HdBranchInfoMapStructMapper.INSTANCE.HdBranchInfoVoToHdBranchInfo(hdBranchInfoVo);
        startPage();
        return getDataTable(hdhcDocUserService.selectList(hdBranchInfo));
    }

    /**
     * 新增用户与预算单位关联关系
     */
    @RequestMapping("/insertUserBranch")
    @CrossOrigin
    public AjaxResult insertUserBranch(@RequestBody List<HdUserBranchVo> hdUserBranchVo) {
        List<HdUserBranch> hdUserBranches = HdUserBranchInfoMapStructMapper.INSTANCE.HdUserBranchInfoVoToHdUserBranchInfo(hdUserBranchVo);
        return toAjax(hdhcDocUserService.batchInsert(hdUserBranches));
    }

    /**
     * 删除用户与预算单位关联关系
     */
    @RequestMapping("/delete")
    public AjaxResult delete(String userInfoId) {
        return toAjax(hdhcDocUserService.delete(userInfoId));
    }


    /**
     * 查询用户有权限的科室
     */
    @RequestMapping("/selectBranchByUser")
    public TableDataInfo selectBranchByUser(String userId) {
        return getDataTable(hdhcDocUserService.selectBranchByUser(userId));
    }
}
